package com.hippo.gateway.filter;

import org.apache.commons.lang3.StringUtils;
import org.springdoc.webflux.ui.SwaggerConfigResource;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

/**
 * @ClassName SpringDocHeaderFilter
 * @Description TODO gateway内置过滤器:用于处理单个路由的请求和响应
 * @Author tangxl
 * @create 2023-03-30 08:48
 **/
@Component
public class SpringDocHeaderFilter extends AbstractGatewayFilterFactory {
    /**
     * 应用过滤器
     * @param config
     * @return
     */
    @Override
    public GatewayFilter apply(Object config) {
//        return ((exchange, chain) -> {
//            ServerHttpRequest request = exchange.getRequest();
//            String path = request.getURI().getPath();
//            System.out.println("path:"+path);
//            if (!StringUtils.endsWithIgnoreCase(path, "/v3/docs")) {
//                return chain.filter(exchange);
//            }
//            ServerHttpRequest newRequest = request.mutate().path("/v3/docs").build();
//            ServerWebExchange newWebExchange = exchange.mutate().request(newRequest).build();
//            return chain.filter(newWebExchange);
//        });
        return null;
    }
}
